/*
 * @Author: your name
 * @Date: 2020-06-06 13:17:04
 * @LastEditTime: 2020-06-08 11:30:02
 * @LastEditors: your name
 * @Description: In User Settings Edit
 * @FilePath: \datamanagerJpa\src\main\java\com\geovis\datamanager\model\BaseEntity.java
 */ 
package com.lg.startertemplate.domain;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import javax.persistence.*;
import java.io.Serializable;
import java.util.Date;

/**
 * 需要在启动类上开启审计模式
 *      创建者
 *      创建时间
 *      最后修改者
 *      最后修改时间
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
@ApiModel
@MappedSuperclass
@EntityListeners(AuditingEntityListener.class)
@JsonIgnoreProperties(value = {"hibernateLazyInitializer", "handler", "fieldHandler"})    //返回序列化问题
public abstract class BaseEntity implements Serializable {
    private static final long serialVersionUID = -8104028530994201645L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    protected Long id;


    //可以在配置文件中全局配置
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    @CreatedDate
    private Date createTime ;

    /**
     * 如此也可以
     */
//    @CreatedDate
//    private Date createTime = new Date();


    /**
     * 在配置文件中配置
     */
    @LastModifiedDate
    private Date updateTime;

}
